package cn.edu.cuit.aumalls.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.edu.cuit.aumalls.entity.CartGoods;
import cn.edu.cuit.aumalls.entity.Goods;
import cn.edu.cuit.aumalls.service.CartService;

@Controller
public class CartController {
	
	@Autowired
	private CartService cartService;
	
	@RequestMapping("/showCart")
	public String showCart(Model model) {
		List<CartGoods> cartgoodslist = cartService.showCartGoods();
		List<Goods> goodslist = cartService.showYouLike(1);
		List<Goods> hotgoods = cartService.showHotSale();
		
		model.addAttribute("list", cartgoodslist);
		model.addAttribute("goodslist", goodslist);
		model.addAttribute("hotgoods", hotgoods);
		
		return "Cart";
	}
	
	@RequestMapping("/deleteOnetItem")
	public String deleteOneCart(@RequestParam(value="goodsId") int goodsId) {
		cartService.deleteOneItem(goodsId);
		return "redirect:/showCart";
	}
	
	@RequestMapping("/addCart")
	public String addOneCart(@RequestParam(value = "goods_name")String goods_name) {
		
		cartService.addGoodsToCart(goods_name);
		
		
		return "redirect:/showCart";
	}

}
